package cn.fei;

/**
 * @ClassName AverageCapitalPlusInterest
 * @Description TODO
 * @Author 郑万富
 * @Date 2020/11/16 10:22
 * @Version 1.0
 */
import java.util.Scanner;
class Money{
    double loanMoney;//贷款本金
    double loanPeriod;//贷款年限
    double yearRate;//总利率
    double month;//还款月数
    double monthlyPayment;//每月金额
    double totalInstrest;//等额利息
    double havePay;//已偿还的贷款
    int fun;//还款方式
    double monthRate;//月利率
    double date;//还款月序号

    double judge(){//计算月利息
        if(month<=120) monthRate=0.003;
        if(month<=240&&month>=120) monthRate=0.004;
        else monthRate=0.006;
        return monthRate;
    }

}
class meanMoney extends Money{//等额本金
    double cal_1(){//计算月供
        return  loanMoney/month+(loanMoney-havePay)*monthRate;

    }
    double cal_2(){//每月应还本金
        return loanMoney/month;
    }
    double cal_3(){//每月应还贷款数
        return (loanMoney-havePay)*monthRate;
    }
    double cal_4(){//每月月供递减
        return loanMoney/month*monthRate;
    }
    double cal_5(){//总利息
        return  ((loanMoney/month+loanMoney*monthRate)+loanMoney/month*(1+monthRate))/2*month-loanMoney;
    }
    void loan1(){
        Money my = new meanMoney();
        meanMoney mm=(meanMoney)my;
        Scanner scan = new Scanner(System.in);
        System.out.print("请输入贷款本金：");
        mm.loanMoney=scan.nextDouble();
        // scan.nextLine();
        System.out.print("请输入已还贷款：");
        mm.havePay=scan.nextDouble();
        // scan.nextLine();
        System.out.print("请输入贷款年限：");
        mm.loanPeriod=scan.nextDouble();
        //scan.nextLine();
        System.out.print("请输入贷款月数：");
        mm.month=scan.nextDouble();
    }
}
class meanRate extends Money{//等息本金
    double rate=Math.pow((1+monthRate),month);
    double temp=Math.pow((1+monthRate),(date-1));
    double cal_1(){//月供额
        return (loanMoney*monthRate*rate/(rate-1));
    }
    double cal_2(){//每月偿还本息
        return (loanMoney*monthRate*rate/(rate-1));
    }
    double cal_3(){//每月偿还利息
        return (loanMoney*monthRate*(rate-temp)/(rate-1));
    }
    double cal_4(){//每月偿还本金
        return  (loanMoney*monthRate*temp/(rate-1));
    }
    double cal_5(){//总利息
        return month*cal_1()-loanMoney;
    }
    void loan2(){
        Money my = new meanRate();
        meanRate mr=(meanRate)my;
        Scanner scan = new Scanner(System.in);
        System.out.print("请输入贷款本金：");
        mr.loanMoney=scan.nextDouble();
        // scan.nextLine();
        System.out.print("请输入已还贷款：");
        mr.havePay=scan.nextDouble();
        // scan.nextLine();
        System.out.print("请输入贷款年限：");
        mr.loanPeriod=scan.nextDouble();
        //scan.nextLine();
        System.out.print("请输入贷款月数：");
        mr.month=scan.nextDouble();

    }
}
public class AverageCapitalPlusInterest {
    public static void main(String[] args) {
        Money my1=new Money();
        Scanner scan=new Scanner(System.in);
       // my.judge();
        System.out.println("请选择你的还款方式，等息本金选择1，等额本金选择2");
        my1.fun=scan.nextInt();
        if(my1.fun==2){
            Money my=new meanRate();
            meanRate mr=(meanRate) my;
            mr.loan2();

            System.out.println("你的月供金额是:"+mr.cal_1()+"\n");
            System.out.println("你一共支付了："+mr.cal_5()+"\n");
        }
        else if(my1.fun==1){
            Money my=new meanMoney();
            meanMoney mm =(meanMoney)my;
            mm.loan1();
            // meanMoney mm=new meanMoney();
            System.out.println("你的月供金额是:"+mm.cal_1()+"\n");
            System.out.println("你一共支付了："+mm.cal_5()+"\n");
        }




        //scan.nextLine();
        /*my.judge();
        System.out.println("请选择你的还款方式，等息本金选择1，等额本金选择2");
        my.fun=scan.nextInt();
        if(my.fun==2){
            meanRate mr=new meanRate();
            //meanRate mr=new meanRate();
            System.out.println("你的月供金额是:"+mr.cal_1()+"\n");
            System.out.println("你一共支付了："+mr.cal_5()+"\n");
        }
        else if(my.fun==1){
            meanMoney mm=new meanMoney();
           // meanMoney mm=new meanMoney();
            System.out.println("你的月供金额是:"+mm.cal_1()+"\n");
            System.out.println("你一共支付了："+mm.cal_5()+"\n");
        }*/
    }
}
